package com.cloud.cloudoauth.oauth.controller;

import com.cloud.cloudoauth.oauth.entity.OauthRefreshTokenEntity;
import com.cloud.cloudoauth.oauth.service.OauthRefreshTokenService;
import com.cloud.cloudoauth.oauth.utils.PageUtils;
import com.cloud.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 
 *
 * @author luoJie
 * @email luoJie@gmail.com
 * @date 2020-09-12 14:45:38
 */
@RestController
@RequestMapping("oauth/oauthrefreshtoken")
public class OauthRefreshTokenController {
    @Autowired
    private OauthRefreshTokenService oauthRefreshTokenService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = oauthRefreshTokenService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{tokenId}")
    public R info(@PathVariable("tokenId") String tokenId){
		OauthRefreshTokenEntity oauthRefreshToken = oauthRefreshTokenService.getById(tokenId);

        return R.ok().put("oauthRefreshToken", oauthRefreshToken);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody OauthRefreshTokenEntity oauthRefreshToken){
		oauthRefreshTokenService.save(oauthRefreshToken);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody OauthRefreshTokenEntity oauthRefreshToken){
		oauthRefreshTokenService.updateById(oauthRefreshToken);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] tokenIds){
		oauthRefreshTokenService.removeByIds(Arrays.asList(tokenIds));

        return R.ok();
    }

}
